/************************新后台js*********************************/
define(function(require) {
	
	var $ = require('jquery1.7');
	var utils = require("utils");
	var ctx = utils.constants.ctx;

	var userService = require("bean/userService");
	var internalEmailService = require("bean/internalEmailService");
	var Confirmbox = require("confirmbox");
	var Validator = require("validator");
	
	var BlackBox = require("blackbox");
	var blackBox = new BlackBox();
	
	$(".wt_handle_userInfo").bind("click",function(){
		var userId = $(this).attr("data").replace("userId_", "");
		window.open(ctx + "/zone/grow_record/" + userId + "#we_main", "_blank");
	});
	
	getEmail();
	setInterval(getEmail, 500);
	function getEmail(){
		var read = internalEmailService.findNoReadEmail();

		$(".noRead").html(read);
	}
	$("#admin-fullscreen").bind("click",function(){
		fullScreen();
	});
	function fullScreen() { 
		var el = document.documentElement; 
		var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen; 

		if (typeof rfs != "undefined" && rfs) { 
			rfs.call(el); 
			} else if (typeof window.ActiveXObject != "undefined") { 
		// for Internet Explorer 
		var wscript = new ActiveXObject("WScript.Shell"); 
		if (wscript != null) { 
				wscript.SendKeys("{F11}"); 
			} 
		} 

	} 
	//修改密码
	var flag = 0;
	$.post(ctx+"/updateUserPassword",function(data){
		var confirmBox = new Confirmbox({
	        trigger: '#updatePassword',
	        title: '修改密码',
	        message: data,
	        onConfirm: function() {
	        	updatePasswordSubmit();
	        }
	    });
		
		confirmBox.after("show",function(){
			/*$("#oldPassword").blur(function(){
				var password = $(this).val();
				if(password!=""){
					if(!userService.checkPassword(password)){
						$(this).next().text("密码有误").css("color","red");
					} else {
						$(this).next().text("请输入旧密码").css("color","#B2B2B2");
					}
				} else {
					$(this).next().text("密码不为空").css("color","red");
				}
			});
			
			
			$("#repeatNewPassword").blur(function(){
				var newPassword = $("#newPassword").val();
				var repeatPassword = $(this).val();
				if(newPassword != repeatPassword){
					$(this).next().text("两次输入密码不一致").css("color","red");
					$("#newPassword").next().text("两次输入密码不一致").css("color","red");
				} else {
					$(this).next().text("请输入密码").css("color","#B2B2B2");
					$("#newPassword").next().text("请确认新密码").css("color","#B2B2B2");
				}
			});*/
			
			
			var validator = new Validator({
	            element: $("#password_form")
	        }).addItem({
	            element: '[name=oldPassword]',
	            required: true,
	            rule: "password"
	        }).addItem({
	            element: '[name=newPassword]',
	            required: true,
	            rule: "password"
	        }).addItem({
	            element: '[name=repeatNewPassword]',
	            required: true,
	            rule: "password"
	        });
		});
		confirmBox.after("hide",function(){
			$("#oldPassword").val("");
			$("#newPassword").val("");
			$("#repeatNewPassword").val("");
		});
	});
	
	function updatePasswordSubmit(){
		
		var oldPassword = $("#oldPassword").val();
		var newPassword = $("#newPassword").val();
		var repeatPassword = $("#repeatNewPassword").val();

		//console.log(userService.checkPassword(oldPassword))
		
		if(!userService.checkPassword(oldPassword)){
			blackBox.alert("原密码输入有误！");
			return;
		}
		if(newPassword != repeatPassword){
			blackBox.alert("两次输入密码不一致!");
			return;
		}
		if(userService.updatePassword(oldPassword,newPassword)){
			blackBox.alert("修改密码成功！");
			location.href = ctx + "/logout";
		} else {
			blackBox.alert("修改密码成功失败！");
		}
	}

	function startMarquee(){
		var insc;
		var this_div=$('#noticeBackIndexNew').parent();
		var _li=$('#noticeBackIndexNew').next().find("li");
		var realSize=_li.size();
		if(realSize<=1){
			return;
		}
		var _ul=$('#noticeBackIndexNew').next();
		var _height=_li.outerHeight();
		var len=_height*realSize;
		var ul_height=2*len;
		_ul.height(ul_height);
		_li.clone().appendTo(_ul);
		_li.find("a").hover(function(){
			insc=0;
		},function(){
			insc=_height;
		})
		var sc=setInterval(function(){
			l=this_div.scrollTop();
			if(l<len-2){
				this_div.animate({scrollTop:l+insc},200);
			}else{
				this_div.scrollTop(0);
			}
			
		},4000);
	}
	
/*	function rollNews(){
		var this_div=$(".wt_notice_info .detail");
		var _li=$('#noticeBackIndexNew').next().find("li");
		var realSize=_li.size();
		if(realSize<=1){
			return;
		}
		var _ul=$('#noticeBackIndexNew').next();
		var _height=_li.height();
		var insc=_height;
		var len=_height*realSize;
		var ul_height=2*len;
		_ul.height(ul_height);
		_li.clone().appendTo(_ul);
		var sc=setInterval(function(){
			l=this_div.scrollTop();
			if(l<len-10){
				this_div.scrollTop(l+insc);
			}else{
				this_div.scrollTop(0);
			}
			
		},4000);
	}*/
	
	//初始设置页面iframe的高度宽度，根据浏览器高宽  wei	
	frameHeight();
	
	function frameHeight(){
	var initWidth=$(window).width()-237;
	var initHeight= $(window).height()-50;
	  $("iframe").css("width",initWidth);//初始设置iframe宽度
	  $("iframe").css("height",initHeight);//初始设置iframe高度
	$(window).resize(function() {
		var resizeWidth=$("body").width()-223;
		var resizeHeight= $(window).height()-50;
//		console.info("++++"+resizeWidth);
//		console.info("++++"+resizeHeight);
		//重新设置高宽 最小宽度
		if(resizeWidth>900){
			  $("iframe").css("width",resizeWidth);
			  $("iframe").css("height",resizeHeight);
		}
		//小于900时出滚动条
		if(resizeWidth<900){
			  $("iframe").attr("scrolling","yes");
			  $("iframe").css("height",resizeHeight);
		}
	
	});
}
	
});



